package com.saas.vertx.common;

import com.saas.enums.SaaSHttpMethod;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: lzqing
 * @Description: 请求url和方法组合类 保存url和方法的映射 用于发布Verticle
 * @Date: Created in 2021/6/6
 */
public class ApiHandler {

    private List<SaaSHttpMethod> SaaSHttpMethods = new ArrayList<>();

    private String api;

    private Handler<RoutingContext> handler;

    private int order;

    public ApiHandler(List<SaaSHttpMethod> SaaSHttpMethods, String api, Handler<RoutingContext> handler) {
        this.SaaSHttpMethods = SaaSHttpMethods;
        this.api = api;
        this.order = RouterVerticle.DEFAULT_ORDER;
        this.handler = handler;
    }

    public ApiHandler(List<SaaSHttpMethod> SaaSHttpMethods, String api, int order, Handler<RoutingContext> handler) {
        this.SaaSHttpMethods = SaaSHttpMethods;
        this.api = api;
        this.order = order;
        this.handler = handler;
    }

    public static List<SaaSHttpMethod> getpost() {
        return CollectionUtils.arrayToList(new SaaSHttpMethod[]{SaaSHttpMethod.GET, SaaSHttpMethod.POST, SaaSHttpMethod.OPTIONS});
    }

    public static List<SaaSHttpMethod> post() {
        return CollectionUtils.arrayToList(new SaaSHttpMethod[]{SaaSHttpMethod.POST, SaaSHttpMethod.OPTIONS});
    }

    public static List<SaaSHttpMethod> delete() {
        return CollectionUtils.arrayToList(new SaaSHttpMethod[]{SaaSHttpMethod.DELETE, SaaSHttpMethod.OPTIONS});
    }

    public static List<SaaSHttpMethod> put() {
        return CollectionUtils.arrayToList(new SaaSHttpMethod[]{SaaSHttpMethod.PUT, SaaSHttpMethod.OPTIONS});
    }

    public static List<SaaSHttpMethod> get() {
        return CollectionUtils.arrayToList(new SaaSHttpMethod[]{SaaSHttpMethod.GET, SaaSHttpMethod.OPTIONS});
    }

    public static List<SaaSHttpMethod> all() {
        return CollectionUtils.arrayToList(new SaaSHttpMethod[]{SaaSHttpMethod.OPTIONS, SaaSHttpMethod.GET, SaaSHttpMethod.HEAD,
                SaaSHttpMethod.POST, SaaSHttpMethod.PUT, SaaSHttpMethod.DELETE,
                SaaSHttpMethod.TRACE, SaaSHttpMethod.CONNECT, SaaSHttpMethod.PATCH
        });
    }

    public List<SaaSHttpMethod> getSaaSHttpMethods() {
        return SaaSHttpMethods;
    }

    public void setSaaSHttpMethods(List<SaaSHttpMethod> SaaSHttpMethods) {
        this.SaaSHttpMethods = SaaSHttpMethods;
    }

    public String getApi() {
        return api;
    }

    public void setApi(String api) {
        this.api = api;
    }

    public Handler<RoutingContext> getHandler() {
        return handler;
    }

    public void setHandler(Handler<RoutingContext> handler) {
        this.handler = handler;
    }

    public int getOrder() {
        return order;
    }

    public void setOrder(int order) {
        this.order = order;
    }
}
